package com.play.game.mydecoration;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.play.game.mydecoration.adapter.MyRecycleViewAdapter;
import com.play.game.mydecoration.view.MyDecoration;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private List<String> list;
    private MyRecycleViewAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        initData();
    }

    private boolean isLinearStyle=true;
    public void SwitchStyle(View view){
        if (!isLinearStyle){
            LinearLayoutManager linerLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
            recyclerView.setLayoutManager(linerLayoutManager);
        }else{
            GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
            recyclerView.setLayoutManager(gridLayoutManager);
        }
        isLinearStyle=!isLinearStyle;

    }



    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.recycleview);

        list = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            list.add("hashiqi ~~~~ "+i);
        }
    }

    private void initData() {
        adapter = new MyRecycleViewAdapter(MainActivity.this,list);
        recyclerView.setAdapter(adapter);

        recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));

        //设置分割线
        recyclerView.addItemDecoration(new MyDecoration());


    }
}
